var Define = require("../../../../lib/Define.js")

var _orderId = 0
var _ware = null

Page({
  data:{
    order:null,
    mainImage:null,
    processList:[]
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    _orderId = options.orderId
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示

    var self = this

    this.requestOrderDetail()
    this.requestProcessList()
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  onWareDetailClick:function(){
    wx.navigateTo({
      url: '/pages/wareDetail/wareDetail?wareId='+_ware.id
    })
  },
  onJinduClick:function(e){
    
  },
  onCuijianClick:function(){
    //催件
    wx.showModal({
        content: "已向您的服务专员发送催件，抱歉让您久等。",
        showCancel: false,
        success: function (res) {
            if (res.confirm) {
                console.log('用户点击确定')
            }
        }
    });

    wx.request({
      url: Define.value.baseUrl+'/app/order/ask?orderId='+_orderId,
      data: {},
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res){
        // success
        console.log(res)
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    })
  },
  requestProcessList:function(userId,crtStep){
      var self = this;

      wx.request({
        url: Define.value.baseUrl+'/app/order/process?orderId='+_orderId+"&bid="+Define.value.bid,
        data: {},
        method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        // header: {}, // 设置请求的 header
        success: function(res){
          // success
          var data = res.data
          if(data.code == 200){
            self.setData({
              processList:data.data
            })
          }
        },
        fail: function() {
          // fail
        },
        complete: function() {
          // complete
        }
      })
  },
  requestOrderDetail:function(){
    var self = this

    wx.request({
      url: Define.value.baseUrl+'/app/order/detail?orderId='+_orderId,
      data: {},
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res){
        // success
        var data = res.data
        _ware = res.data.data.ware

        self.setData({
          order:data.data,
          mainImage:data.data.ware.images[0].url
        })
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },
  onProcessClick:function(e){
    var value = e.currentTarget.dataset
    
    var canPush = false
    if(value.action.length>0 && value.step <= (value.crtstep+1)){
      canPush = true
    }
    else if(value.action.length && value.step <= value.crtstep){
      canPush = true
    }

    wx.navigateTo({
      url: "../../../orderProcessDetail/orderProcessDetail?orderId="+_orderId+"&step="+value.step,
      success: function(res){
        // success
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    })
  }
})